Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document evaluation results table with pagination #300

Merged
merged 2 commits into from
Sep 30, 2024

Conversation

andresgutgon
Copy link
Contributor

@andresgutgon andresgutgon commented Sep 27, 2024

What?

Paginate document evaluation results and refactor pagination Refactor pagination to make it more generic and easy to use in any table we want to add pagination

Issue

#283

TODO

  • Generic paginateQuery method
  • Fix document logs table after refactor
  • Fix types for augmented query select
  • Fix wip work on refactoring lib/pagination/* I left this broken. Start here
  • Paginate evaluation results table
  • New styles for pagination in table bottom
  • Evaluation ID result needs to be a page not a layout because NextJS doesn't receive searchParams in layouts
  • Log detail in /logs and evaluation results need to be scrollable

Next PR

  • Add tests to paginateQuery
  • DRY sidebar document info and use the right design as commented here

@andresgutgon andresgutgon added the 🚧 wip Work in progress label Sep 27, 2024
@andresgutgon andresgutgon force-pushed the feature/paginate-document-evaluation-results-table branch 2 times, most recently from cc39e83 to 1a85bbc Compare September 27, 2024 16:02
project: ctx.project,
filterByStatus: input.status,
})
.$dynamic(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No so bad in the end. We just need to invoke $dynamic() in our queries and it will be paginated and fully typed

const rows = await query.limit(pageSize).offset((page - 1) * pageSize)
const count = rows[0]?.__count ? Number(rows[0]?.__count) : 0
return [rows, count]
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repositiries are not the right place to put pagination concerns. Now one doubt I have is with the generic Repository.findAll(). Now it executes the query. I think would be better to return the query and use the paginateQuery service to let it do the pagination work. I wont do this refactor here

But what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm i think it's weird ideally you want the repository.findall method to return the results not the query, any way we can integrate the pagination into the findall method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pagination is page aware in the sense that you have to pass a base URL to generate
< prev and next > URLs. We can pass this prop to the findAll but it feels weird to me. For what I saw in Rails word pagination is aware of ORM but ORM is not aware of pagination.

image

No big deal whatever you prefer

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm ya, well then yes i would remove the findall method from repositories all together and use the scope plus the new pagination method you created

@@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest'
import { mergeCommit } from '../../services/commits'
import { updateDocument } from '../../services/documents'
import * as factories from '../../tests/factories'
import { computeDocumentLogsWithMetadata } from './computeDocumentLogsWithMetadata'
import { computeDocumentLogsWithMetadataQuery } from './computeDocumentLogsWithMetadata'
Copy link
Contributor Author

@andresgutgon andresgutgon Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By convention if a query service return the lazy query call it [something]Query so we know

@andresgutgon andresgutgon force-pushed the feature/paginate-document-evaluation-results-table branch from 2374049 to 1bba8fc Compare September 28, 2024 17:10
onSelect={setSelectedTab}
/>
<div className='flex flex-col relative w-full h-full max-h-full max-w-full overflow-auto'>
<div
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this wrapper classes are supper similar between

  1. Evaluation log info side panel
  2. Evaluation original log modal panel
  3. Log sidebar info panel
image

Probably is there an abstraction. For now I'll leave un-DRY

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that you are at it maybe we can implement the correct design for the original log design
image

const { workspace } = await getCurrentUser()
const evaluationScope = new EvaluationsRepository(workspace.id)
return evaluationScope.find(id).then((r) => r.unwrap())
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that evaluation is fetched in layout and page is a perfect use case for cache

@andresgutgon andresgutgon force-pushed the feature/paginate-document-evaluation-results-table branch from 1bba8fc to 67f6f25 Compare September 28, 2024 17:16
const { data: evaluationResults, mutate } = useEvaluationResultsWithMetadata(
{
evaluationId: evaluation.id,
documentUuid: document.documentUuid,
commitUuid: commit.uuid,
projectId: project.id,
page,
pageSize,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess was that because a different page means a different URL all the client is wipe out. But that's not the case and when you move to page 2 you still see cached page 1 in the client. So I did that the store also is aware of pagination in the cache key so whenever change it make a new fetch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be taken into account when we introduce filters in evaluation results table

documentUuid: string
evaluationId: string
}
searchParams: QueryParams
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So before this changes everthing was in the layout and create batch modal was route URL. This is not possible because query params (search params) are not revalidated in layouts so I need to convert results table in a page

More info:
https://nextjs.org/docs/app/api-reference/file-conventions/layout#layouts-do-not-receive-searchparams

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classic question: is this messing with any modals in subroutes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, create batch was a route and now is not because if we keep as route the table is not visible when open

documentUuid: params.documentUuid,
draft: commit,
}).$dynamic(),
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really happy with the final API of paginateQuery it does 2 things:

  1. Paginate the SQL query
  2. Generates a IPagination object to be consumed by pagination UI components

}) {
const [selectedTab, setSelectedTab] = useState<string>('metadata')
const ref = useRef<HTMLDivElement>(null)
const height = useDynamicHeight({ ref, paddingBottom: 16 })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh man, web apps with scrollable areas are not as easy as doing web pages. I don't care what DHH says

</div>
</div>
)}
{visibleMessages.map((message, index) => (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hiding messages is gone cc @cesr

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why didn't we like this? in evaluations it's useless to see a ultra long conversation chain in a width of 150 pixels

@andresgutgon andresgutgon removed the 🚧 wip Work in progress label Sep 28, 2024
Refactor pagination to make it more generic and easy to use in any table
we want to add pagination
@andresgutgon andresgutgon force-pushed the feature/paginate-document-evaluation-results-table branch from 67f6f25 to 2e875a1 Compare September 28, 2024 17:29
@@ -47,7 +47,8 @@ describe('DocumentVersionsRepository', () => {

const documents = result.unwrap()
expect(documents).toHaveLength(2)
expect(documents.map((d) => d.path)).toEqual(['foo', 'bar'])
const paths = documents.map((d) => d.path).sort()
expect(paths).toEqual(['bar', 'foo'])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Troll test failing in my branch. I didn't touch this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this route now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside ./Actions/**.tsx component. Now is not a route

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like wat? We have been here before

Copy link
Collaborator

@geclos geclos Sep 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well it's a pretty uncommon modal so ok this time,but please let's not make it a common thing that we remove modal from routes and into components

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also is this so important? What we lost in this specific case?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's why i said this

well it's a pretty uncommon modal so ok this time

not super important in this case. But since you ask we lose the ability to directly link to the creation modal if we ever want to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I wrote my message yours was not in the UI. Lo del real time

@andresgutgon andresgutgon merged commit b29a724 into main Sep 30, 2024
4 checks passed
@andresgutgon andresgutgon deleted the feature/paginate-document-evaluation-results-table branch September 30, 2024 06:59
@github-actions github-actions bot locked and limited conversation to collaborators Sep 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants